<?php

/**
 * Static content controller.
 *
 * This file will render views from views/pages/
 *
 * PHP 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       app.Controller
 * @since         CakePHP(tm) v 0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
App::uses('FrontController', 'Controller');

/**
 * Static content controller
 *
 * Override this controller by placing a copy in controllers directory of an application
 *
 * @package       app.Controller
 * @link http://book.cakephp.org/2.0/en/controllers/pages-controller.html
 */
class IndexController extends FrontController {

    /**
     * Controller name
     *
     * @var string
     */
    public $name = 'Index';

    /**
     * Model used
     * @var array
     */
    public $uses = array('Content', 'Category');

    /**
     * Displays a view
     *
     * @param mixed What page to display
     * @return void
     */
    public function index() {
        $categories = $this->Category->find('all', array('conditions' => array('parent_id' => 0,'approved'=>1)));
        $this->set('categories', $categories);
        $this->set('title_for_layout', 'Free Web Directory');
    }

    public function display() {
        $x = unserialize(Cache::read("maincat", "5year"));
        $key = array_search($this->params->url, $x);
        
        // search category
        $cat = $this->params->url;
        $categories = $this->Category->find('all', array('conditions' => array('parent_id' => $key,'approved'=>1)));
        $this->set('categories', $categories);

        // show websites
        $result = $this->Content->find('all', array('conditions' => array('category_id' => $key,'approved'=>1)));
        $this->set('result', $result);
        /*        if (count($this->params['pass']) > 0) {
          #d($this->params['pass']);
          } else {
          // main cat
          d($this->params);
          }
         */
    }

}
